﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using AdventureWorksLT.Views.Customers.ViewModels;

namespace AdventureWorksLT.Views.Customers.Controls
{
    public partial class SalesOrderHeaderWorkWithGrid : Page
    {

        public SalesOrderHeaderWorkWithGrid()
        {
            //CustomersViewModel.DashLoad_PK = 0;
            //MessageBox.Show(AdventureWorksLT.Views.Customers.ViewModels.SalesOrderHeadersViewModel.DashLoad_PK.ToString());
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {


        }
        

        
        public static int CSalesOrderID;
        private void ObtainSalesOrderID()
        {

            string a = SalesOrderHeadersDataGrid.SelectedItem.ToString();
            int i = a.IndexOf(":") + 1;
            a = a.Substring(i);
            int dashLoadPk;
            int.TryParse(a, out dashLoadPk);
            CustomersViewModel.DashLoad_PK = dashLoadPk;
            CSalesOrderID = dashLoadPk;
        }
        
      

        private static void Failed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            MessageBox.Show("Exception " + e.Exception);
        }
        

        private void GoToSalesOrderHeaderButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            ObtainSalesOrderID();
            Uri target = new Uri("/Customers/Controls/SalesOrderHeaderControl?SalesOrderID=" + CustomersViewModel.DashLoad_PK, UriKind.Relative);
            NavigationService.NavigationFailed += new NavigationFailedEventHandler(Failed);
             if (NavigationService != null) NavigationService.Navigate(target);
        }

    }
    }


